const prompts = require("prompts");

async function selectEnv(local = true) {
  const choices = [
    {
      title: '体验环境',
      value: 'trial',
    },
    {
      title: '正式环境',
      value: 'release',
    },
  ];

  if (local) {
    choices.unshift(
      {
        title: '开发环境',
        value: 'develop',
      })
  } else {
    choices.push({
      title: '自定义',
      value: 'custom',
    })
  }

  let resp = await prompts([
    {
      type: 'select',
      name: 'env',
      message: '请选择运行环境',
      choices,
    },
  ]);

  if (resp.env === 'custom') {
    resp = await prompts([
      {
        type: 'text',
        name: 'env',
        message: '请输入运行环境',
      }
    ])
  }

  console.log(resp)

  return resp.env;
}

exports.selectEnv = selectEnv;
